package datamining.parsers;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Serializable;
import java.io.Writer;
import java.text.ParseException;
import java.util.Collection;

import datamining.sequence.Sequence;
import datamining.sequence.SequenceFactory;

/** 
 * 创建于 2012-11-14 下午11:01:05
 * 
 * @author xujinghu (jinghuxu@nudt.edu.cn)
 * 
 * 版权所有 2012 xujinghu
 * 
 * 许可证 Apache
 */
public interface SequenceParser<ItemType> extends Serializable {

	/** @return the item parser used */
	public LabelParser<ItemType> getNodeParser();
	
	/**
	 * parses multiple sequences for the given input stream and creates a
	 * collection of the corresponding sequences
	 * 
	 * @param io
	 * @param factory
	 *            a factory that creates a corresponding empty sequence
	 * @return a collection of the represented sequence
	 * @throws ParseException
	 * @throws IOException
	 */
	public Collection<Sequence<ItemType>> parse(InputStream io,
			SequenceFactory<ItemType> factory) throws ParseException,
			IOException;
	
	public Collection<Sequence<ItemType>> parse(Reader reader,
			SequenceFactory<ItemType> factory) throws ParseException,
			IOException;
	/**
	 * parses one sequence from the given input string and creates the sequence that
	 * is represented by it
	 * 
	 * @param input
	 * @param factory
	 *            a factory that creates a corresponding empty Sequence
	 * @return the corrsponding Sequence
	 * @throws ParseException
	 *             if the input string cannot be parsed correctly
	 */
	public Sequence<ItemType> parse(String input,
			SequenceFactory<ItemType> factory) throws ParseException;

	/**
	 * @param Sequence
	 * @return a serialized representation of the given Sequence
	 */
	public String serialize(Sequence<ItemType> Sequence);

	/**
	 * writes all serialized representations of the given sequences to the output
	 * stream
	 * 
	 * @param out
	 * @param sequences
	 * @throws IOException
	 */
	public void serialize(OutputStream out,
			Collection<Sequence<ItemType>> sequences) throws IOException;
	
	public Collection<Sequence<ItemType>> parse(Writer writer,
			SequenceFactory<ItemType> factory) throws ParseException,
			IOException;
}
